<html>
<head>
  <script src="../lib/OpenLayers.js"></script>
  <script type="text/javascript"><!--
    var isMozilla = (navigator.userAgent.indexOf("compatible") == -1);
    var map; 
    function test_01_Events_constructor (t) {
        t.plan( 21 );
        var obj = {result: 0}, eventTypes = ["doThingA", "doThingB", "doThingC"];
        events = new OpenLayers.Events(obj, $('map'), eventTypes);
        t.ok( events instanceof OpenLayers.Events, "new OpenLayers.Control returns object" );
        if (!isMozilla)
            t.ok( true, "skipping element test outside of Mozilla");
        else
            t.ok( events.div instanceof HTMLDivElement, "events.div isa HTMLDivElement" );
        t.ok( events.object === obj, "events.object is the object we passed" );

        var builtin = OpenLayers.Events.prototype.BROWSER_EVENTS;
        for (var i = 0; i < builtin.length; i++) {
            t.ok( events.listeners[builtin[i]] instanceof Array, 
                    builtin[i] + " builtin listener isa Array" );
        }
        for (var i = 0; i < eventTypes.length; i++) {
            t.ok( events.listeners[eventTypes[i]] instanceof Array, 
                    eventTypes[i] + " custom listener isa Array" );
        }

        t.eq( events.listeners["this doesn't exist"], null, "undefined event handler is none" );

        var func = function () { this.result++ }
        events.register( "doThingA", obj, func );
        t.eq( events.listeners["doThingA"].length, 1, "register correctly sets event.listener" );

        t.eq( obj.result, 0, "result is 0 before we call triggerEvent" );
        events.triggerEvent("doThingA", {});
        t.eq( obj.result, 1, "result is 1 after we call triggerEvent" );
        events.triggerEvent("doThingA");
        t.eq( obj.result, 2, "result is 2 after we call triggerEvent with no event" );
    }
    function test_02_Events_nullEventTypes (t) {
        t.plan(1);
        events = new OpenLayers.Events(null, $('map'), null);
        t.ok( events.listeners, "Creation of Events with null Event Types is okay" );
    }
  // -->
  </script>
</head>
<body>
    <div id="map" style="width: 1024px; height: 512px;"/>
</body>
</html>
